return QString from html_entitize, xml_entitize. (#897)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Sun, 31 Jul 2022 17:59:34 +0000 (11:59 -0600)
committerGitHub <noreply@github.com>
Sun, 31 Jul 2022 17:59:34 +0000 (11:59 -0600)
defs.h
html.cc
kml.cc
osm.cc
util.cc

diff --git a/defs.h b/defs.h
index e7888608392be142cd6a443076722d62313e9272..352c65a334d11094f6a7e8531fb9453265e6da71 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -1079,8 +1079,8 @@ QDateTime dotnet_time_to_qdatetime(long long dotnet);
 const char* get_cache_icon(const Waypoint* waypointp);
 const char* gs_get_cachetype(geocache_type t);
 const char* gs_get_container(geocache_container t);
-char* xml_entitize(const char* str);
-char* html_entitize(const QString& str);
+QString xml_entitize(const QString& str);
+QString html_entitize(const QString& str);
 char* strip_html(const utf_string*);
 char* strip_nastyhtml(const QString& in);
 char* convert_human_date_format(const char* human_datef);      /* "MM,YYYY,DD" -> "%m,%Y,%d" */
diff --git a/html.cc b/html.cc
index 8f3c0773551c934b740b0650fded75236b944b1c..e84507f7117a086ed3a9bd11d05d42b907bc3e18 100644 (file)
--- a/html.cc
+++ b/html.cc
@@ -75,10 +75,9 @@ HtmlFormat::html_disp(const Waypoint* wpt) const
   gbfprintf(file_out, "<br>\n");
   if (wpt->description != wpt->shortname) {
     if (wpt->HasUrlLink()) {
-      char* d = html_entitize(wpt->description);
-      UrlLink link = wpt->GetUrlLink();
-      gbfprintf(file_out, "<a href=\"%s\">%s</a>", CSTR(link.url_), d);
-      xfree(d);
+      gbfputs(QStringLiteral("<a href=\"%1\">%2</a>")
+              .arg(wpt->GetUrlLink().url_, html_entitize(wpt->description)),
+              file_out);
     } else {
       gbfprintf(file_out, "%s", CSTR(wpt->description));
     }
@@ -139,9 +138,9 @@ HtmlFormat::html_disp(const Waypoint* wpt) const
 
         logpart = xml_findfirst(curlog, "groundspeak:finder");
         if (logpart) {
-          char* f = html_entitize(logpart->cdata);
-          gbfprintf(file_out, "<span class=\"gpsbabellogfinder\">%s</span> on ", f);
-          xfree(f);
+          gbfputs(QStringLiteral("<span class=\"gpsbabellogfinder\">%1</span> on ")
+                  .arg(html_entitize(logpart->cdata)),
+                  file_out);
         }
 
         logpart = xml_findfirst(curlog, "groundspeak:date");
@@ -178,9 +177,7 @@ HtmlFormat::html_disp(const Waypoint* wpt) const
             s = logpart->cdata;
           }
 
-          char* t = html_entitize(s);
-          gbfputs(t, file_out);
-          xfree(t);
+          gbfputs(html_entitize(s), file_out);
         }
 
         gbfprintf(file_out, "</p>\n");
@@ -194,13 +191,9 @@ HtmlFormat::html_disp(const Waypoint* wpt) const
 void
 HtmlFormat::html_index(const Waypoint* wpt) const
 {
-  char* sn = html_entitize(wpt->shortname);
-  char* d = html_entitize(wpt->description);
-
-  gbfprintf(file_out, "<a href=\"#%s\">%s - %s</a><br>\n", sn, sn, d);
-
-  xfree(sn);
-  xfree(d);
+  gbfputs(QStringLiteral("<a href=\"#%1\">%1 - %2</a><br>\n")
+          .arg(html_entitize(wpt->shortname), html_entitize(wpt->description)),
+          file_out);
 }
 
 void
diff --git a/kml.cc b/kml.cc
index fbb5b04ca632dcd359c5e4c53e92a2a3af20de0d..bf56c1dfff9592d445c216719d10d882ab390b30 100644 (file)
--- a/kml.cc
+++ b/kml.cc
@@ -1238,10 +1238,8 @@ QString KmlFormat::kml_geocache_get_logs(const Waypoint* wpt) const
         s = logpart->cdata;
       }
 
-      r = r + "<br />";
-      char* t = html_entitize(s);
-      r = r + t;
-      xfree(t);
+      r += "<br />";
+      r += html_entitize(s);
     }
 
     r += "</p>";
diff --git a/osm.cc b/osm.cc
index 7e4e9077a77825d2d9876a4cc8a0d90ec04df00b..b1066117dc69b6fd13fdfe404b8ca70502731f88 100644 (file)
--- a/osm.cc
+++ b/osm.cc
@@ -63,7 +63,7 @@ const char* const OsmFormat::osm_features[] = {
   nullptr
 };
 
-  /* based on <http://wiki.openstreetmap.org/index.php/Map_Features> */
+/* based on <http://wiki.openstreetmap.org/index.php/Map_Features> */
 
 const OsmFormat::osm_icon_mapping_t OsmFormat::osm_icon_mappings[] = {
 
@@ -661,9 +661,9 @@ void
 OsmFormat::osm_write_tag(const QString& key, const QString& value) const
 {
   if (!value.isEmpty()) {
-    char* str = xml_entitize(CSTR(value));
-    gbfprintf(fout, "    <tag k='%s' v='%s'/>\n", CSTR(key), str);
-    xfree(str);
+    gbfputs(QStringLiteral("    <tag k='%1' v='%2'/>\n")
+            .arg(key, xml_entitize(value)),
+            fout);
   }
 }
 
diff --git a/util.cc b/util.cc
index 362b680a9e642ce678159f1c10d6d2c43777222d..b722ee00deb77389f970f235bf182de219abeb88 100644 (file)
--- a/util.cc
+++ b/util.cc
@@ -1395,7 +1395,7 @@ entity_types stdentities[] =  {
 };
 
 static
-char*
+QString
 entitize(const char* str, bool is_html)
 {
   char* p;
@@ -1442,19 +1442,21 @@ entitize(const char* str, bool is_html)
     }
   }
 
-  return (tmp);
+  QString rv(tmp);
+  xfree(tmp);
+  return rv;
 }
 
 /*
  * Public callers for the above to hide the absence of &apos from HTML
  */
 
-char* xml_entitize(const char* str)
+QString xml_entitize(const QString& str)
 {
-  return entitize(str, false);
+  return entitize(CSTR(str), false);
 }
 
-char* html_entitize(const QString& str)
+QString html_entitize(const QString& str)
 {
   return entitize(CSTR(str), true);
 }